<template>
  <div>
    <el-row>
      <Echarts :option="option" style="height: 600px; width: 900px" />
    </el-row>
  </div>
</template>

<script>
//引入Echart的包
import Echarts from "../components/charts/Echarts";
import { getCarbonFlowRecord, getCarbonPotentialRecord } from "@/api/zoushi";

export default {
  components: {
    Echarts,
  },
  data() {
    return {
      potentialRecord: [],
      carbonFlowRecord: [],
      option: {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            crossStyle: {
              color: "#999",
            },
          },
        },
        toolbox: {
          feature: {
            dataView: { show: true, readOnly: false },
            magicType: { show: true, type: ["line", "bar"] },
            restore: { show: true },
            saveAsImage: { show: true },
          },
        },
        legend: {
          data: ["碳流", "碳势"],
        },
        xAxis: [
          {
            type: "category",
            // data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
            axisPointer: {
              type: "shadow",
            },
          },
        ],
        yAxis: [
          {
            type: "value",
            name: "碳势",
            min: 0,
            max: 250,
            interval: 50,
            axisLabel: {
              formatter: "{value}",
            },
          },
          {
            type: "value",
            name: "碳流",
            min: 0,
            max: 25,
            interval: 5,
            axisLabel: {
              formatter: "{value}",
            },
          },
        ],
        series: [
          {
            name: "碳流",
            type: "bar",
            tooltip: {
              valueFormatter: function (value) {
                return value + " ml";
              },
            },
            data: this.carbonFlowRecord,
          },
          {
            name: "碳势",
            type: "line",
            yAxisIndex: 1,
            tooltip: {
              valueFormatter: function (value) {
                return value + " °C";
              },
            },
            data: this.potentialRecord,
          },
        ],
      },
    };
  },
  mounted() {
    getCarbonFlowRecord(1).then((res) => {
      this.carbonFlowRecord = res.data;
    });
    getCarbonPotentialRecord(1).then((res) => {
      this.potentialRecord = res.data;
    });
  },
};
</script>
<style scoped>
</style>